<?php
import( 'classes.core.View' );
import( 'classes.logic.Server' );
import( 'classes.logic.Project' );
import( 'classes.logic.ServerProject' );
import( 'classes.logic.Run' );
/**
 *  Builds a select Box, to select Server and Project Environment.
 *	@package		mv2.disposal.preparation
 *	@extends		Core_View
 *	@author			Dritan Latifi <dritan@gmail.com>
 *	@since			17.07.2007
 *	@version		0.1
 */
/**
 *  Builds a select Box, to select Server and Project Environment.
 *	@package		mv2.disposal.preparation
 *	@extends		Core_View
 *	@author			Dritan Latifi <dritan@gmail.com>
 *	@since			17.07.2007
 *	@version		0.1
 */
class View_Panel_EnvironmentSelector extends Core_View
{
	private	$showServerProjects	= false;
	private	$showServers		= false;
	private	$showProjects		= false;
	private	$showRuns			= false;

	function setServerProjects( $show = true )
	{
		$this->showServerProjects	= $show;
	}

	function setServers( $show = true )
	{
		$this->showServers	= $show;
	}

	function setProjects( $show = true )
	{
		$this->showProjects	= $show;
	}

	function setRuns( $show = true )
	{
		$this->showRuns	= $show;
	}

	function buildContent()
	{
		$session		= Framework_Krypton_Core_Registry::getStatic('session');
		$request		= Framework_Krypton_Core_Registry::getStatic( 'request' );
		$words			= $this->words['main']['selectEnvironment'];

		$serverProjectId	= $session->get( 'serverProjectId' );

		if( $this->showServerProjects )
		{
			$optServerprojects	= array( 0 => '---------' );
			$serverProjects	= Logic_ServerProject::getServerProjectList();
			foreach( $serverProjects as $serverProject )
			{
				$server		= Logic_Server::getServerTitle( $serverProject['server_id'] );
				$project	= Logic_Project::getProjectTitle( $serverProject['project_id'] );
				$optServerprojects[$serverProject['server_project_id']]	= $server." -> ".$project;
			}
			$optServerprojects['_selected']	= $serverProjectId;
			$serverProjects		= UI_HTML_Elements::Select( 'selectServerProjectId', $optServerprojects, 'l', false, 'selectEnvironment' );
			$ui['label_serverprojects']	= UI_HTML_Elements::Label( 'selectServerProjectId', $words['serverproject'] );		
			$ui['field_serverprojects']	= UI_HTML_Elements::Field( 'selectServerProjectId', $serverProjects );
		}
		if( $this->showServers )
		{
			$serverId	= $session->get( 'serverId' );
			$opt_server	= array( 0 => '---------' );
			$logic		= new Logic_Server();
			$servers	= $logic->getServers( true );
			foreach( $servers as $id => $title )
				$opt_server[$id]	= $title;
			$opt_server['_selected'] = $serverId;
			$servers		= UI_HTML_Elements::Select( 'selectServerId', $opt_server, 'l', false, 'selectEnvironment' );
			$ui['label_servers']	= UI_HTML_Elements::Label( 'selectServerId', $words['server'] );		
			$ui['field_servers']	= UI_HTML_Elements::Field( 'selectServerId', $servers );
		}
		if( $this->showProjects )
		{
			$opt_project	= array( 0 => '---------' );
	//		if( $serverId )
	//		{
				$projects	= Logic_Project::getProjects( true );

				foreach( $projects as $id => $title )
					$opt_project[$id]	= $title;
				$opt_project['_selected'] = $session->get( 'projectId' );
	//		}
			$platforms		= UI_HTML_Elements::Select( 'selectProjectId', $opt_project, 'l', false, 'selectEnvironment' );
			$ui['label_projects']	= UI_HTML_Elements::Label( 'selectProjectId', $words['project'] );
			$ui['field_projects']	= UI_HTML_Elements::Field( 'selectProjectId', $platforms );
		}
		if( $this->showRuns )
		{
			$opt_run	= array( 0 => '---------' );

			if( $serverProjectId )
			{
				$runs	= Logic_Run::getRunList( $serverProjectId );
				foreach( $runs as $run )
					$opt_run[$run['run_id']]	= $run['title'];
				$opt_run['_selected']	= $session->get( 'runId' );
			}
			$runs		= UI_HTML_Elements::Select( 'selectRunId', $opt_run, 'l', false, 'selectEnvironment' );
			$ui['label_runs']	= UI_HTML_Elements::Label( 'selectRunId', $words['run'] );
			$ui['field_runs']	= UI_HTML_Elements::Field( 'selectRunId', $runs );
		}

		$button			= UI_HTML_Elements::Button( 'selectFrontend', $words['button'] );
		$ui['field_button']		= UI_HTML_Elements::Field( '', $button );
		$ui['form']				= UI_HTML_Elements::Form( 'selectEnvironment', "?link=".$request->get('link')."&selectEnvironment" );
		$ui['caption']			= UI_HTML_Elements::TableCaption( $words['caption'], 'filter' );
		$ui['colgroup']			= UI_HTML_Elements::ColumnGroup( $words['colgroup'] );
		$ui['heading']			= $words['heading'];
		return $this->loadTemplate( 'environment', $ui );
	}
}
?>